<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\model;

/**
 * 工单回复模型
 */
class ApplicationBanker extends ModelBase
{
    protected $insert = ['create_time'];

    /**
     * 时间自动完成
     */
    public function setCreateTimeAttr()
    {

        return TIME_NOW;
    }
    /**
     * 时间获取器
     */
    public function getCreateTimeAttr($value)
    {

        return date('Y-m-d H:i:s',$value);
    }

    /**
     * 查询余额
     */

    public function  getUserBalanceAttr(){
        $user_arr=[
            'userName'=>$this->username
        ];
        $time=TIME_NOW;
        $sign=md5($time.json_encode($user_arr).'ty25w3f8jkgg1xw633ypkg16');
        $header_sign=$sign.'_'.$time;
        $heades=[
            'X-Signature-Code:'.$header_sign,
        ];
        $res=mycurl($this->account_address.'/api/external/balance',json_encode($user_arr),1,$heades);
        $res=json_decode($res,true);
        if($res){
            return $res['data'];
        }
        return  '接口出错';

    }



    /**
     * 查询余额
     */

    public function  getKingBalanceAttr(){
        $user_arr=[
            'userName'=>$this->pwd
        ];
        $time=TIME_NOW;
        $sign=md5($time.json_encode($user_arr).'ty25w3f8jkgg1xw633ypkg16');
        $header_sign=$sign.'_'.$time;
        $heades=[
            'X-Signature-Code:'.$header_sign,
        ];
        $res=mycurl($this->account_address.'/api/external/balance',json_encode($user_arr),1,$heades);
        $res=json_decode($res,true);
        if($res){
            return $res['data'];
        }
        return  '接口出错';

    }

    /***
     * 下注总金额
     */
    public function  get_bet_money($username){
        $total=GamesLog::where(['app_id'=>$this->id,'bet_username'=>$username,'state'=>1])->sum('number')+0;
        return $total;
    }




}
